﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Flit.Samples.Validation
{
    partial class Validation
    {
        public List<string> Errors { get; set; }
    }



    public partial class StringLength
    {
        private StringValue Value
        {
            get { return (StringValue) Parent; }
        }


        partial void OnLongerThan(int minLength)
        {
            AddErrorMessageIf(x => x.Length < minLength, Value.Value, Value.Name, "must be more than " + minLength + " characters");
        }

        partial void OnShorterThan(int maxLength)
        {
            AddErrorMessageIf(x => x.Length > maxLength, Value.Value, Value.Name, "must be less than " + maxLength + " characters");
        }
    }

    public partial class IntegerValidation
    {
        private IntegerValue Value
        {
            get { return (IntegerValue) Parent; }
        }

        partial void OnGreaterThan(long minValue)
        {
            AddErrorMessageIf(x => x < minValue, Value.Value, Value.Name, "must be greater than " + minValue);
        }

        partial void OnLessThan(long maxValue)
        {
            AddErrorMessageIf(x => x > maxValue, Value.Value, Value.Name, "must be less than " + maxValue);
        }
    }

    public partial class FloatValidation
    {
        private FloatValue Value
        {
            get { return (FloatValue) Parent; }
        }


        partial void OnARealNumber()
        {
            AddErrorMessageIf(x => !(double.IsNaN(x)), Value.Value, Value.Name, "must be a real number");
        }

        partial void OnGreaterThan(double minValue)
        {
            AddErrorMessageIf(x => x < minValue, Value.Value, Value.Name, "must be greater than " + minValue);
        }

        partial void OnLessThan(double maxValue)
        {
            AddErrorMessageIf(x => x > maxValue, Value.Value, Value.Name, "must be less than " + maxValue);
        }

        partial void OnNotInfinity()
        {
            AddErrorMessageIf(double.IsNegativeInfinity, Value.Value, Value.Name, "cannot be infinity");
            AddErrorMessageIf(double.IsPositiveInfinity, Value.Value, Value.Name, "cannot be infinity");
        }
    }
}
